home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / tools / gcc / gcc270_src.lha / gcc-2.7.0-amiga / gcc.info-11 < prev    next >
Encoding:
GNU Info File  |  1995-06-16  |  41.6 KB  |  953 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.55 from the input
  2. file gcc.texi.
  3.  
  4.    This file documents the use and the internals of the GNU compiler.
  5.  
  6.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  7. Boston, MA 02111-1307 USA
  8.  
  9.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995 Free Software
  10. Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided also
  18. that the sections entitled "GNU General Public License," "Funding for
  19. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  20. included exactly as in the original, and provided that the entire
  21. resulting derived work is distributed under the terms of a permission
  22. notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that the sections entitled "GNU General Public
  27. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  28. `Look And Feel'", and this permission notice, may be included in
  29. translations approved by the Free Software Foundation instead of in the
  30. original English.
  31.  
  32. 
  33. File: gcc.info,  Node: Cross-Compiler Problems,  Next: Interoperation,  Prev: Installation Problems,  Up: Trouble
  34.  
  35. Cross-Compiler Problems
  36. =======================
  37.  
  38.    You may run into problems with cross compilation on certain machines,
  39. for several reasons.
  40.  
  41.    * Cross compilation can run into trouble for certain machines because
  42.      some target machines' assemblers require floating point numbers to
  43.      be written as *integer* constants in certain contexts.
  44.  
  45.      The compiler writes these integer constants by examining the
  46.      floating point value as an integer and printing that integer,
  47.      because this is simple to write and independent of the details of
  48.      the floating point representation.  But this does not work if the
  49.      compiler is running on a different machine with an incompatible
  50.      floating point format, or even a different byte-ordering.
  51.  
  52.      In addition, correct constant folding of floating point values
  53.      requires representing them in the target machine's format.  (The C
  54.      standard does not quite require this, but in practice it is the
  55.      only way to win.)
  56.  
  57.      It is now possible to overcome these problems by defining macros
  58.      such as `REAL_VALUE_TYPE'.  But doing so is a substantial amount of
  59.      work for each target machine.  *Note Cross-compilation::.
  60.  
  61.    * At present, the program `mips-tfile' which adds debug support to
  62.      object files on MIPS systems does not work in a cross compile
  63.      environment.
  64.  
  65. 
  66. File: gcc.info,  Node: Interoperation,  Next: External Bugs,  Prev: Cross-Compiler Problems,  Up: Trouble
  67.  
  68. Interoperation
  69. ==============
  70.  
  71.    This section lists various difficulties encountered in using GNU C or
  72. GNU C++ together with other compilers or with the assemblers, linkers,
  73. libraries and debuggers on certain systems.
  74.  
  75.    * Objective C does not work on the RS/6000.
  76.  
  77.    * GNU C++ does not do name mangling in the same way as other C++
  78.      compilers.  This means that object files compiled with one compiler
  79.      cannot be used with another.
  80.  
  81.      This effect is intentional, to protect you from more subtle
  82.      problems.  Compilers differ as to many internal details of C++
  83.      implementation, including: how class instances are laid out, how
  84.      multiple inheritance is implemented, and how virtual function
  85.      calls are handled.  If the name encoding were made the same, your
  86.      programs would link against libraries provided from other
  87.      compilers--but the programs would then crash when run.
  88.      Incompatible libraries are then detected at link time, rather than
  89.      at run time.
  90.  
  91.    * Older GDB versions sometimes fail to read the output of GNU CC
  92.      version 2.  If you have trouble, get GDB version 4.4 or later.
  93.  
  94.    * DBX rejects some files produced by GNU CC, though it accepts
  95.      similar constructs in output from PCC.  Until someone can supply a
  96.      coherent description of what is valid DBX input and what is not,
  97.      there is nothing I can do about these problems.  You are on your
  98.      own.
  99.  
  100.    * The GNU assembler (GAS) does not support PIC.  To generate PIC
  101.      code, you must use some other assembler, such as `/bin/as'.
  102.  
  103.    * On some BSD systems, including some versions of Ultrix, use of
  104.      profiling causes static variable destructors (currently used only
  105.      in C++) not to be run.
  106.  
  107.    * Use of `-I/usr/include' may cause trouble.
  108.  
  109.      Many systems come with header files that won't work with GNU CC
  110.      unless corrected by `fixincludes'.  The corrected header files go
  111.      in a new directory; GNU CC searches this directory before
  112.      `/usr/include'.  If you use `-I/usr/include', this tells GNU CC to
  113.      search `/usr/include' earlier on, before the corrected headers.
  114.      The result is that you get the uncorrected header files.
  115.  
  116.      Instead, you should use these options (when compiling C programs):
  117.  
  118.           -I/usr/local/lib/gcc-lib/TARGET/VERSION/include -I/usr/include
  119.  
  120.      For C++ programs, GNU CC also uses a special directory that
  121.      defines C++ interfaces to standard C subroutines.  This directory
  122.      is meant to be searched *before* other standard include
  123.      directories, so that it takes precedence.  If you are compiling
  124.      C++ programs and specifying include directories explicitly, use
  125.      this option first, then the two options above:
  126.  
  127.           -I/usr/local/lib/g++-include
  128.  
  129.    * On some SGI systems, when you use `-lgl_s' as an option, it gets
  130.      translated magically to `-lgl_s -lX11_s -lc_s'.  Naturally, this
  131.      does not happen when you use GNU CC.  You must specify all three
  132.      options explicitly.
  133.  
  134.    * On a Sparc, GNU CC aligns all values of type `double' on an 8-byte
  135.      boundary, and it expects every `double' to be so aligned.  The Sun
  136.      compiler usually gives `double' values 8-byte alignment, with one
  137.      exception: function arguments of type `double' may not be aligned.
  138.  
  139.      As a result, if a function compiled with Sun CC takes the address
  140.      of an argument of type `double' and passes this pointer of type
  141.      `double *' to a function compiled with GNU CC, dereferencing the
  142.      pointer may cause a fatal signal.
  143.  
  144.      One way to solve this problem is to compile your entire program
  145.      with GNU CC.  Another solution is to modify the function that is
  146.      compiled with Sun CC to copy the argument into a local variable;
  147.      local variables are always properly aligned.  A third solution is
  148.      to modify the function that uses the pointer to dereference it via
  149.      the following function `access_double' instead of directly with
  150.      `*':
  151.  
  152.           inline double
  153.           access_double (double *unaligned_ptr)
  154.           {
  155.             union d2i { double d; int i[2]; };
  156.           
  157.             union d2i *p = (union d2i *) unaligned_ptr;
  158.             union d2i u;
  159.           
  160.             u.i[0] = p->i[0];
  161.             u.i[1] = p->i[1];
  162.           
  163.             return u.d;
  164.           }
  165.  
  166.      Storing into the pointer can be done likewise with the same union.
  167.  
  168.    * On Solaris, the `malloc' function in the `libmalloc.a' library may
  169.      allocate memory that is only 4 byte aligned.  Since GNU CC on the
  170.      Sparc assumes that doubles are 8 byte aligned, this may result in a
  171.      fatal signal if doubles are stored in memory allocated by the
  172.      `libmalloc.a' library.
  173.  
  174.      The solution is to not use the `libmalloc.a' library.  Use instead
  175.      `malloc' and related functions from `libc.a'; they do not have
  176.      this problem.
  177.  
  178.    * Sun forgot to include a static version of `libdl.a' with some
  179.      versions of SunOS (mainly 4.1).  This results in undefined symbols
  180.      when linking static binaries (that is, if you use `-static').  If
  181.      you see undefined symbols `_dlclose', `_dlsym' or `_dlopen' when
  182.      linking, compile and link against the file `mit/util/misc/dlsym.c'
  183.      from the MIT version of X windows.
  184.  
  185.    * The 128-bit long double format that the Sparc port supports
  186.      currently works by using the architecturally defined quad-word
  187.      floating point instructions.  Since there is no hardware that
  188.      supports these instructions they must be emulated by the operating
  189.      system.  Long doubles do not work in Sun OS versions 4.0.3 and
  190.      earlier, because the kernel eumulator uses an obsolete and
  191.      incompatible format.  Long doubles do not work in Sun OS version
  192.      4.1.1 due to a problem in a Sun library.  Long doubles do work on
  193.      Sun OS versions 4.1.2 and higher, but GNU CC does not enable them
  194.      by default.  Long doubles appear to work in Sun OS 5.x (Solaris
  195.      2.x).
  196.  
  197.    * On HP-UX version 9.01 on the HP PA, the HP compiler `cc' does not
  198.      compile GNU CC correctly.  We do not yet know why.  However, GNU CC
  199.      compiled on earlier HP-UX versions works properly on HP-UX 9.01
  200.      and can compile itself properly on 9.01.
  201.  
  202.    * On the HP PA machine, ADB sometimes fails to work on functions
  203.      compiled with GNU CC.  Specifically, it fails to work on functions
  204.      that use `alloca' or variable-size arrays.  This is because GNU CC
  205.      doesn't generate HP-UX unwind descriptors for such functions.  It
  206.      may even be impossible to generate them.
  207.  
  208.    * Debugging (`-g') is not supported on the HP PA machine, unless you
  209.      use the preliminary GNU tools (*note Installation::.).
  210.  
  211.    * Taking the address of a label may generate errors from the HP-UX
  212.      PA assembler.  GAS for the PA does not have this problem.
  213.  
  214.    * Using floating point parameters for indirect calls to static
  215.      functions will not work when using the HP assembler.  There simply
  216.      is no way for GCC to specify what registers hold arguments for
  217.      static functions when using the HP assembler.  GAS for the PA does
  218.      not have this problem.
  219.  
  220.    * In extremely rare cases involvving some very large functions you
  221.      may receive errors from the HP linker complaining about an out of
  222.      bounds unconditional branch offset.  This used to occur more often
  223.      in previous versions of GNU CC, but is now exceptionally rare.  If
  224.      you should run into it, you can work around by making your
  225.      function smaller.
  226.  
  227.    * GNU CC compiled code sometimes emits warnings from the HP-UX
  228.      assembler of the form:
  229.  
  230.           (warning) Use of GR3 when
  231.             frame >= 8192 may cause conflict.
  232.  
  233.      These warnings are harmless and can be safely ignored.
  234.  
  235.    * The current version of the assembler (`/bin/as') for the RS/6000
  236.      has certain problems that prevent the `-g' option in GCC from
  237.      working.  Note that `Makefile.in' uses `-g' by default when
  238.      compiling `libgcc2.c'.
  239.  
  240.      IBM has produced a fixed version of the assembler.  The upgraded
  241.      assembler unfortunately was not included in any of the AIX 3.2
  242.      update PTF releases (3.2.2, 3.2.3, or 3.2.3e).  Users of AIX 3.1
  243.      should request PTF U403044 from IBM and users of AIX 3.2 should
  244.      request PTF U416277.  See the file `README.RS6000' for more
  245.      details on these updates.
  246.  
  247.      You can test for the presense of a fixed assembler by using the
  248.      command
  249.  
  250.           as -u < /dev/null
  251.  
  252.      If the command exits normally, the assembler fix already is
  253.      installed.  If the assembler complains that "-u" is an unknown
  254.      flag, you need to order the fix.
  255.  
  256.    * On the IBM RS/6000, compiling code of the form
  257.  
  258.           extern int foo;
  259.           
  260.           ... foo ...
  261.           
  262.           static int foo;
  263.  
  264.      will cause the linker to report an undefined symbol `foo'.
  265.      Although this behavior differs from most other systems, it is not a
  266.      bug because redefining an `extern' variable as `static' is
  267.      undefined in ANSI C.
  268.  
  269.    * AIX on the RS/6000 provides support (NLS) for environments outside
  270.      of the United States.  Compilers and assemblers use NLS to support
  271.      locale-specific representations of various objects including
  272.      floating-point numbers ("." vs "," for separating decimal
  273.      fractions).  There have been problems reported where the library
  274.      linked with GCC does not produce the same floating-point formats
  275.      that the assembler accepts.  If you have this problem, set the
  276.      LANG environment variable to "C" or "En_US".
  277.  
  278.    * Even if you specify `-fdollars-in-identifiers', you cannot
  279.      successfully use `$' in identifiers on the RS/6000 due to a
  280.      restriction in the IBM assembler.  GAS supports these identifiers.
  281.  
  282.    * On the RS/6000, XLC version 1.3.0.0 will miscompile `jump.c'.  XLC
  283.      version 1.3.0.1 or later fixes this problem.  You can obtain
  284.      XLC-1.3.0.2 by requesting PTF 421749 from IBM.
  285.  
  286.    * There is an assembler bug in versions of DG/UX prior to 5.4.2.01
  287.      that occurs when the `fldcr' instruction is used.  GNU CC uses
  288.      `fldcr' on the 88100 to serialize volatile memory references.  Use
  289.      the option `-mno-serialize-volatile' if your version of the
  290.      assembler has this bug.
  291.  
  292.    * On VMS, GAS versions 1.38.1 and earlier may cause spurious warning
  293.      messages from the linker.  These warning messages complain of
  294.      mismatched psect attributes.  You can ignore them.  *Note VMS
  295.      Install::.
  296.  
  297.    * On NewsOS version 3, if you include both of the files `stddef.h'
  298.      and `sys/types.h', you get an error because there are two typedefs
  299.      of `size_t'.  You should change `sys/types.h' by adding these
  300.      lines around the definition of `size_t':
  301.  
  302.           #ifndef _SIZE_T
  303.           #define _SIZE_T
  304.           ACTUAL TYPEDEF HERE
  305.           #endif
  306.  
  307.    * On the Alliant, the system's own convention for returning
  308.      structures and unions is unusual, and is not compatible with GNU
  309.      CC no matter what options are used.
  310.  
  311.    * On the IBM RT PC, the MetaWare HighC compiler (hc) uses a different
  312.      convention for structure and union returning.  Use the option
  313.      `-mhc-struct-return' to tell GNU CC to use a convention compatible
  314.      with it.
  315.  
  316.    * On Ultrix, the Fortran compiler expects registers 2 through 5 to
  317.      be saved by function calls.  However, the C compiler uses
  318.      conventions compatible with BSD Unix: registers 2 through 5 may be
  319.      clobbered by function calls.
  320.  
  321.      GNU CC uses the same convention as the Ultrix C compiler.  You can
  322.      use these options to produce code compatible with the Fortran
  323.      compiler:
  324.  
  325.           -fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
  326.  
  327.    * On the WE32k, you may find that programs compiled with GNU CC do
  328.      not work with the standard shared C library.  You may need to link
  329.      with the ordinary C compiler.  If you do so, you must specify the
  330.      following options:
  331.  
  332.           -L/usr/local/lib/gcc-lib/we32k-att-sysv/2.7.0 -lgcc -lc_s
  333.  
  334.      The first specifies where to find the library `libgcc.a' specified
  335.      with the `-lgcc' option.
  336.  
  337.      GNU CC does linking by invoking `ld', just as `cc' does, and there
  338.      is no reason why it *should* matter which compilation program you
  339.      use to invoke `ld'.  If someone tracks this problem down, it can
  340.      probably be fixed easily.
  341.  
  342.    * On the Alpha, you may get assembler errors about invalid syntax as
  343.      a result of floating point constants.  This is due to a bug in the
  344.      C library functions `ecvt', `fcvt' and `gcvt'.  Given valid
  345.      floating point numbers, they sometimes print `NaN'.
  346.  
  347.    * On Irix 4.0.5F (and perhaps in some other versions), an assembler
  348.      bug sometimes reorders instructions incorrectly when optimization
  349.      is turned on.  If you think this may be happening to you, try
  350.      using the GNU assembler; GAS version 2.1 supports ECOFF on Irix.
  351.  
  352.      Or use the `-noasmopt' option when you compile GNU CC with itself,
  353.      and then again when you compile your program.  (This is a temporary
  354.      kludge to turn off assembler optimization on Irix.)  If this
  355.      proves to be what you need, edit the assembler spec in the file
  356.      `specs' so that it unconditionally passes `-O0' to the assembler,
  357.      and never passes `-O2' or `-O3'.
  358.  
  359. 
  360. File: gcc.info,  Node: External Bugs,  Next: Incompatibilities,  Prev: Interoperation,  Up: Trouble
  361.  
  362. Problems Compiling Certain Programs
  363. ===================================
  364.  
  365.    Certain programs have problems compiling.
  366.  
  367.    * Parse errors may occur compiling X11 on a Decstation running
  368.      Ultrix 4.2 because of problems in DEC's versions of the X11 header
  369.      files `X11/Xlib.h' and `X11/Xutil.h'.  People recommend adding
  370.      `-I/usr/include/mit' to use the MIT versions of the header files,
  371.      using the `-traditional' switch to turn off ANSI C, or fixing the
  372.      header files by adding this:
  373.  
  374.           #ifdef __STDC__
  375.           #define NeedFunctionPrototypes 0
  376.           #endif
  377.  
  378.    * If you have trouble compiling Perl on a SunOS 4 system, it may be
  379.      because Perl specifies `-I/usr/ucbinclude'.  This accesses the
  380.      unfixed header files.  Perl specifies the options
  381.  
  382.           -traditional -Dvolatile=__volatile__
  383.           -I/usr/include/sun -I/usr/ucbinclude
  384.           -fpcc-struct-return
  385.  
  386.      most of which are unnecessary with GCC 2.4.5 and newer versions.
  387.      You can make a properly working Perl by setting `ccflags' to
  388.      `-fwritable-strings' (implied by the `-traditional' in the
  389.      original options) and `cppflags' to empty in `config.sh', then
  390.      typing `./doSH; make depend; make'.
  391.  
  392.    * On various 386 Unix systems derived from System V, including SCO,
  393.      ISC, and ESIX, you may get error messages about running out of
  394.      virtual memory while compiling certain programs.
  395.  
  396.      You can prevent this problem by linking GNU CC with the GNU malloc
  397.      (which thus replaces the malloc that comes with the system).  GNU
  398.      malloc is available as a separate package, and also in the file
  399.      `src/gmalloc.c' in the GNU Emacs 19 distribution.
  400.  
  401.      If you have installed GNU malloc as a separate library package,
  402.      use this option when you relink GNU CC:
  403.  
  404.           MALLOC=/usr/local/lib/libgmalloc.a
  405.  
  406.      Alternatively, if you have compiled `gmalloc.c' from Emacs 19, copy
  407.      the object file to `gmalloc.o' and use this option when you relink
  408.      GNU CC:
  409.  
  410.           MALLOC=gmalloc.o
  411.  
  412. 
  413. File: gcc.info,  Node: Incompatibilities,  Next: Fixed Headers,  Prev: External Bugs,  Up: Trouble
  414.  
  415. Incompatibilities of GNU CC
  416. ===========================
  417.  
  418.    There are several noteworthy incompatibilities between GNU C and most
  419. existing (non-ANSI) versions of C.  The `-traditional' option
  420. eliminates many of these incompatibilities, *but not all*, by telling
  421. GNU C to behave like the other C compilers.
  422.  
  423.    * GNU CC normally makes string constants read-only.  If several
  424.      identical-looking string constants are used, GNU CC stores only one
  425.      copy of the string.
  426.  
  427.      One consequence is that you cannot call `mktemp' with a string
  428.      constant argument.  The function `mktemp' always alters the string
  429.      its argument points to.
  430.  
  431.      Another consequence is that `sscanf' does not work on some systems
  432.      when passed a string constant as its format control string or
  433.      input.  This is because `sscanf' incorrectly tries to write into
  434.      the string constant.  Likewise `fscanf' and `scanf'.
  435.  
  436.      The best solution to these problems is to change the program to use
  437.      `char'-array variables with initialization strings for these
  438.      purposes instead of string constants.  But if this is not possible,
  439.      you can use the `-fwritable-strings' flag, which directs GNU CC to
  440.      handle string constants the same way most C compilers do.
  441.      `-traditional' also has this effect, among others.
  442.  
  443.    * `-2147483648' is positive.
  444.  
  445.      This is because 2147483648 cannot fit in the type `int', so
  446.      (following the ANSI C rules) its data type is `unsigned long int'.
  447.      Negating this value yields 2147483648 again.
  448.  
  449.    * GNU CC does not substitute macro arguments when they appear inside
  450.      of string constants.  For example, the following macro in GNU CC
  451.  
  452.           #define foo(a) "a"
  453.  
  454.      will produce output `"a"' regardless of what the argument A is.
  455.  
  456.      The `-traditional' option directs GNU CC to handle such cases
  457.      (among others) in the old-fashioned (non-ANSI) fashion.
  458.  
  459.    * When you use `setjmp' and `longjmp', the only automatic variables
  460.      guaranteed to remain valid are those declared `volatile'.  This is
  461.      a consequence of automatic register allocation.  Consider this
  462.      function:
  463.  
  464.           jmp_buf j;
  465.           
  466.           foo ()
  467.           {
  468.             int a, b;
  469.           
  470.             a = fun1 ();
  471.             if (setjmp (j))
  472.               return a;
  473.           
  474.             a = fun2 ();
  475.             /* `longjmp (j)' may occur in `fun3'. */
  476.             return a + fun3 ();
  477.           }
  478.  
  479.      Here `a' may or may not be restored to its first value when the
  480.      `longjmp' occurs.  If `a' is allocated in a register, then its
  481.      first value is restored; otherwise, it keeps the last value stored
  482.      in it.
  483.  
  484.      If you use the `-W' option with the `-O' option, you will get a
  485.      warning when GNU CC thinks such a problem might be possible.
  486.  
  487.      The `-traditional' option directs GNU C to put variables in the
  488.      stack by default, rather than in registers, in functions that call
  489.      `setjmp'.  This results in the behavior found in traditional C
  490.      compilers.
  491.  
  492.    * Programs that use preprocessing directives in the middle of macro
  493.      arguments do not work with GNU CC.  For example, a program like
  494.      this will not work:
  495.  
  496.           foobar (
  497.           #define luser
  498.                   hack)
  499.  
  500.      ANSI C does not permit such a construct.  It would make sense to
  501.      support it when `-traditional' is used, but it is too much work to
  502.      implement.
  503.  
  504.    * Declarations of external variables and functions within a block
  505.      apply only to the block containing the declaration.  In other
  506.      words, they have the same scope as any other declaration in the
  507.      same place.
  508.  
  509.      In some other C compilers, a `extern' declaration affects all the
  510.      rest of the file even if it happens within a block.
  511.  
  512.      The `-traditional' option directs GNU C to treat all `extern'
  513.      declarations as global, like traditional compilers.
  514.  
  515.    * In traditional C, you can combine `long', etc., with a typedef
  516.      name, as shown here:
  517.  
  518.           typedef int foo;
  519.           typedef long foo bar;
  520.  
  521.      In ANSI C, this is not allowed: `long' and other type modifiers
  522.      require an explicit `int'.  Because this criterion is expressed by
  523.      Bison grammar rules rather than C code, the `-traditional' flag
  524.      cannot alter it.
  525.  
  526.    * PCC allows typedef names to be used as function parameters.  The
  527.      difficulty described immediately above applies here too.
  528.  
  529.    * PCC allows whitespace in the middle of compound assignment
  530.      operators such as `+='.  GNU CC, following the ANSI standard, does
  531.      not allow this.  The difficulty described immediately above
  532.      applies here too.
  533.  
  534.    * GNU CC complains about unterminated character constants inside of
  535.      preprocessing conditionals that fail.  Some programs have English
  536.      comments enclosed in conditionals that are guaranteed to fail; if
  537.      these comments contain apostrophes, GNU CC will probably report an
  538.      error.  For example, this code would produce an error:
  539.  
  540.           #if 0
  541.           You can't expect this to work.
  542.           #endif
  543.  
  544.      The best solution to such a problem is to put the text into an
  545.      actual C comment delimited by `/*...*/'.  However, `-traditional'
  546.      suppresses these error messages.
  547.  
  548.    * Many user programs contain the declaration `long time ();'.  In the
  549.      past, the system header files on many systems did not actually
  550.      declare `time', so it did not matter what type your program
  551.      declared it to return.  But in systems with ANSI C headers, `time'
  552.      is declared to return `time_t', and if that is not the same as
  553.      `long', then `long time ();' is erroneous.
  554.  
  555.      The solution is to change your program to use `time_t' as the
  556.      return type of `time'.
  557.  
  558.    * When compiling functions that return `float', PCC converts it to a
  559.      double.  GNU CC actually returns a `float'.  If you are concerned
  560.      with PCC compatibility, you should declare your functions to return
  561.      `double'; you might as well say what you mean.
  562.  
  563.    * When compiling functions that return structures or unions, GNU CC
  564.      output code normally uses a method different from that used on most
  565.      versions of Unix.  As a result, code compiled with GNU CC cannot
  566.      call a structure-returning function compiled with PCC, and vice
  567.      versa.
  568.  
  569.      The method used by GNU CC is as follows: a structure or union
  570.      which is 1, 2, 4 or 8 bytes long is returned like a scalar.  A
  571.      structure or union with any other size is stored into an address
  572.      supplied by the caller (usually in a special, fixed register, but
  573.      on some machines it is passed on the stack).  The
  574.      machine-description macros `STRUCT_VALUE' and
  575.      `STRUCT_INCOMING_VALUE' tell GNU CC where to pass this address.
  576.  
  577.      By contrast, PCC on most target machines returns structures and
  578.      unions of any size by copying the data into an area of static
  579.      storage, and then returning the address of that storage as if it
  580.      were a pointer value.  The caller must copy the data from that
  581.      memory area to the place where the value is wanted.  GNU CC does
  582.      not use this method because it is slower and nonreentrant.
  583.  
  584.      On some newer machines, PCC uses a reentrant convention for all
  585.      structure and union returning.  GNU CC on most of these machines
  586.      uses a compatible convention when returning structures and unions
  587.      in memory, but still returns small structures and unions in
  588.      registers.
  589.  
  590.      You can tell GNU CC to use a compatible convention for all
  591.      structure and union returning with the option
  592.      `-fpcc-struct-return'.
  593.  
  594.    * GNU C complains about program fragments such as `0x74ae-0x4000'
  595.      which appear to be two hexadecimal constants separated by the minus
  596.      operator.  Actually, this string is a single "preprocessing token".
  597.      Each such token must correspond to one token in C.  Since this
  598.      does not, GNU C prints an error message.  Although it may appear
  599.      obvious that what is meant is an operator and two values, the ANSI
  600.      C standard specifically requires that this be treated as erroneous.
  601.  
  602.      A "preprocessing token" is a "preprocessing number" if it begins
  603.      with a digit and is followed by letters, underscores, digits,
  604.      periods and `e+', `e-', `E+', or `E-' character sequences.
  605.  
  606.      To make the above program fragment valid, place whitespace in
  607.      front of the minus sign.  This whitespace will end the
  608.      preprocessing number.
  609.  
  610. 
  611. File: gcc.info,  Node: Fixed Headers,  Next: Standard Libraries,  Prev: Incompatibilities,  Up: Trouble
  612.  
  613. Fixed Header Files
  614. ==================
  615.  
  616.    GNU CC needs to install corrected versions of some system header
  617. files.  This is because most target systems have some header files that
  618. won't work with GNU CC unless they are changed.  Some have bugs, some
  619. are incompatible with ANSI C, and some depend on special features of
  620. other compilers.
  621.  
  622.    Installing GNU CC automatically creates and installs the fixed header
  623. files, by running a program called `fixincludes' (or for certain
  624. targets an alternative such as `fixinc.svr4').  Normally, you don't
  625. need to pay attention to this.  But there are cases where it doesn't do
  626. the right thing automatically.
  627.  
  628.    * If you update the system's header files, such as by installing a
  629.      new system version, the fixed header files of GNU CC are not
  630.      automatically updated.  The easiest way to update them is to
  631.      reinstall GNU CC.  (If you want to be clever, look in the makefile
  632.      and you can find a shortcut.)
  633.  
  634.    * On some systems, in particular SunOS 4, header file directories
  635.      contain machine-specific symbolic links in certain places.  This
  636.      makes it possible to share most of the header files among hosts
  637.      running the same version of SunOS 4 on different machine models.
  638.  
  639.      The programs that fix the header files do not understand this
  640.      special way of using symbolic links; therefore, the directory of
  641.      fixed header files is good only for the machine model used to
  642.      build it.
  643.  
  644.      In SunOS 4, only programs that look inside the kernel will notice
  645.      the difference between machine models.  Therefore, for most
  646.      purposes, you need not be concerned about this.
  647.  
  648.      It is possible to make separate sets of fixed header files for the
  649.      different machine models, and arrange a structure of symbolic
  650.      links so as to use the proper set, but you'll have to do this by
  651.      hand.
  652.  
  653.    * On Lynxos, GNU CC by default does not fix the header files.  This
  654.      is because bugs in the shell cause the `fixincludes' script to
  655.      fail.
  656.  
  657.      This means you will encounter problems due to bugs in the system
  658.      header files.  It may be no comfort that they aren't GNU CC's
  659.      fault, but it does mean that there's nothing for us to do about
  660.      them.
  661.  
  662. 
  663. File: gcc.info,  Node: Standard Libraries,  Next: Disappointments,  Prev: Fixed Headers,  Up: Trouble
  664.  
  665. Standard Libraries
  666. ==================
  667.  
  668.    GNU CC by itself attempts to be what the ISO/ANSI C standard calls a
  669. "conforming freestanding implementation".  This means all ANSI C
  670. language features are available, as well as the contents of `float.h',
  671. `limits.h', `stdarg.h', and `stddef.h'.  The rest of the C library is
  672. supplied by the vendor of the operating system.  If that C library
  673. doesn't conform to the C standards, then your programs might get
  674. warnings (especially when using `-Wall') that you don't expect.
  675.  
  676.    For example, the `sprintf' function on SunOS 4.1.3 returns `char *'
  677. while the C standard says that `sprintf' returns an `int'.  The
  678. `fixincludes' program could make the prototype for this function match
  679. the Standard, but that would be wrong, since the function will still
  680. return `char *'.
  681.  
  682.    If you need a Standard compliant library, then you need to find one,
  683. as GNU CC does not provide one.  The GNU C library (called `glibc') has
  684. been ported to a number of operating systems, and provides ANSI/ISO,
  685. POSIX, BSD and SystemV compatibility.  You could also ask your operating
  686. system vendor if newer libraries are available.
  687.  
  688. 
  689. File: gcc.info,  Node: Disappointments,  Next: C++ Misunderstandings,  Prev: Standard Libraries,  Up: Trouble
  690.  
  691. Disappointments and Misunderstandings
  692. =====================================
  693.  
  694.    These problems are perhaps regrettable, but we don't know any
  695. practical way around them.
  696.  
  697.    * Certain local variables aren't recognized by debuggers when you
  698.      compile with optimization.
  699.  
  700.      This occurs because sometimes GNU CC optimizes the variable out of
  701.      existence.  There is no way to tell the debugger how to compute the
  702.      value such a variable "would have had", and it is not clear that
  703.      would be desirable anyway.  So GNU CC simply does not mention the
  704.      eliminated variable when it writes debugging information.
  705.  
  706.      You have to expect a certain amount of disagreement between the
  707.      executable and your source code, when you use optimization.
  708.  
  709.    * Users often think it is a bug when GNU CC reports an error for code
  710.      like this:
  711.  
  712.           int foo (struct mumble *);
  713.           
  714.           struct mumble { ... };
  715.           
  716.           int foo (struct mumble *x)
  717.           { ... }
  718.  
  719.      This code really is erroneous, because the scope of `struct
  720.      mumble' in the prototype is limited to the argument list
  721.      containing it.  It does not refer to the `struct mumble' defined
  722.      with file scope immediately below--they are two unrelated types
  723.      with similar names in different scopes.
  724.  
  725.      But in the definition of `foo', the file-scope type is used
  726.      because that is available to be inherited.  Thus, the definition
  727.      and the prototype do not match, and you get an error.
  728.  
  729.      This behavior may seem silly, but it's what the ANSI standard
  730.      specifies.  It is easy enough for you to make your code work by
  731.      moving the definition of `struct mumble' above the prototype.
  732.      It's not worth being incompatible with ANSI C just to avoid an
  733.      error for the example shown above.
  734.  
  735.    * Accesses to bitfields even in volatile objects works by accessing
  736.      larger objects, such as a byte or a word.  You cannot rely on what
  737.      size of object is accessed in order to read or write the bitfield;
  738.      it may even vary for a given bitfield according to the precise
  739.      usage.
  740.  
  741.      If you care about controlling the amount of memory that is
  742.      accessed, use volatile but do not use bitfields.
  743.  
  744.    * GNU CC comes with shell scripts to fix certain known problems in
  745.      system header files.  They install corrected copies of various
  746.      header files in a special directory where only GNU CC will
  747.      normally look for them.  The scripts adapt to various systems by
  748.      searching all the system header files for the problem cases that
  749.      we know about.
  750.  
  751.      If new system header files are installed, nothing automatically
  752.      arranges to update the corrected header files.  You will have to
  753.      reinstall GNU CC to fix the new header files.  More specifically,
  754.      go to the build directory and delete the files `stmp-fixinc' and
  755.      `stmp-headers', and the subdirectory `include'; then do `make
  756.      install' again.
  757.  
  758.    * On 68000 systems, you can get paradoxical results if you test the
  759.      precise values of floating point numbers.  For example, you can
  760.      find that a floating point value which is not a NaN is not equal
  761.      to itself.  This results from the fact that the the floating point
  762.      registers hold a few more bits of precision than fit in a `double'
  763.      in memory.  Compiled code moves values between memory and floating
  764.      point registers at its convenience, and moving them into memory
  765.      truncates them.
  766.  
  767.      You can partially avoid this problem by using the `-ffloat-store'
  768.      option (*note Optimize Options::.).
  769.  
  770.    * On the MIPS, variable argument functions using `varargs.h' cannot
  771.      have a floating point value for the first argument.  The reason
  772.      for this is that in the absence of a prototype in scope, if the
  773.      first argument is a floating point, it is passed in a floating
  774.      point register, rather than an integer register.
  775.  
  776.      If the code is rewritten to use the ANSI standard `stdarg.h'
  777.      method of variable arguments, and the prototype is in scope at the
  778.      time of the call, everything will work fine.
  779.  
  780. 
  781. File: gcc.info,  Node: C++ Misunderstandings,  Next: Protoize Caveats,  Prev: Disappointments,  Up: Trouble
  782.  
  783. Common Misunderstandings with GNU C++
  784. =====================================
  785.  
  786.    C++ is a complex language and an evolving one, and its standard
  787. definition (the ANSI C++ draft standard) is also evolving.  As a result,
  788. your C++ compiler may occasionally surprise you, even when its behavior
  789. is correct.  This section discusses some areas that frequently give
  790. rise to questions of this sort.
  791.  
  792. * Menu:
  793.  
  794. * Static Definitions::  Static member declarations are not definitions
  795. * Temporaries::         Temporaries may vanish before you expect
  796.  
  797. 
  798. File: gcc.info,  Node: Static Definitions,  Next: Temporaries,  Up: C++ Misunderstandings
  799.  
  800. Declare *and* Define Static Members
  801. -----------------------------------
  802.  
  803.    When a class has static data members, it is not enough to *declare*
  804. the static member; you must also *define* it.  For example:
  805.  
  806.      class Foo
  807.      {
  808.        ...
  809.        void method();
  810.        static int bar;
  811.      };
  812.  
  813.    This declaration only establishes that the class `Foo' has an `int'
  814. named `Foo::bar', and a member function named `Foo::method'.  But you
  815. still need to define *both* `method' and `bar' elsewhere.  According to
  816. the draft ANSI standard, you must supply an initializer in one (and
  817. only one) source file, such as:
  818.  
  819.      int Foo::bar = 0;
  820.  
  821.    Other C++ compilers may not correctly implement the standard
  822. behavior.  As a result, when you switch to `g++' from one of these
  823. compilers, you may discover that a program that appeared to work
  824. correctly in fact does not conform to the standard: `g++' reports as
  825. undefined symbols any static data members that lack definitions.
  826.  
  827. 
  828. File: gcc.info,  Node: Temporaries,  Prev: Static Definitions,  Up: C++ Misunderstandings
  829.  
  830. Temporaries May Vanish Before You Expect
  831. ----------------------------------------
  832.  
  833.    It is dangerous to use pointers or references to *portions* of a
  834. temporary object.  The compiler may very well delete the object before
  835. you expect it to, leaving a pointer to garbage.  The most common place
  836. where this problem crops up is in classes like the libg++ `String'
  837. class, that define a conversion function to type `char *' or `const
  838. char *'.  However, any class that returns a pointer to some internal
  839. structure is potentially subject to this problem.
  840.  
  841.    For example, a program may use a function `strfunc' that returns
  842. `String' objects, and another function `charfunc' that operates on
  843. pointers to `char':
  844.  
  845.      String strfunc ();
  846.      void charfunc (const char *);
  847.  
  848. In this situation, it may seem natural to write
  849. `charfunc (strfunc ());' based on the knowledge that class `String' has
  850. an explicit conversion to `char' pointers.  However, what really
  851. happens is akin to `charfunc (strfunc ().convert ());', where the
  852. `convert' method is a function to do the same data conversion normally
  853. performed by a cast.  Since the last use of the temporary `String'
  854. object is the call to the conversion function, the compiler may delete
  855. that object before actually calling `charfunc'.  The compiler has no
  856. way of knowing that deleting the `String' object will invalidate the
  857. pointer.  The pointer then points to garbage, so that by the time
  858. `charfunc' is called, it gets an invalid argument.
  859.  
  860.    Code like this may run successfully under some other compilers,
  861. especially those that delete temporaries relatively late.  However, the
  862. GNU C++ behavior is also standard-conformant, so if your program depends
  863. on late destruction of temporaries it is not portable.
  864.  
  865.    If you think this is surprising, you should be aware that the ANSI
  866. C++ committee continues to debate the lifetime-of-temporaries problem.
  867.  
  868.    For now, at least, the safe way to write such code is to give the
  869. temporary a name, which forces it to remain until the end of the scope
  870. of the name.  For example:
  871.  
  872.      String& tmp = strfunc ();
  873.      charfunc (tmp);
  874.  
  875. 
  876. File: gcc.info,  Node: Protoize Caveats,  Next: Non-bugs,  Prev: C++ Misunderstandings,  Up: Trouble
  877.  
  878. Caveats of using `protoize'
  879. ===========================
  880.  
  881.    The conversion programs `protoize' and `unprotoize' can sometimes
  882. change a source file in a way that won't work unless you rearrange it.
  883.  
  884.    * `protoize' can insert references to a type name or type tag before
  885.      the definition, or in a file where they are not defined.
  886.  
  887.      If this happens, compiler error messages should show you where the
  888.      new references are, so fixing the file by hand is straightforward.
  889.  
  890.    * There are some C constructs which `protoize' cannot figure out.
  891.      For example, it can't determine argument types for declaring a
  892.      pointer-to-function variable; this you must do by hand.  `protoize'
  893.      inserts a comment containing `???' each time it finds such a
  894.      variable; so you can find all such variables by searching for this
  895.      string.  ANSI C does not require declaring the argument types of
  896.      pointer-to-function types.
  897.  
  898.    * Using `unprotoize' can easily introduce bugs.  If the program
  899.      relied on prototypes to bring about conversion of arguments, these
  900.      conversions will not take place in the program without prototypes.
  901.      One case in which you can be sure `unprotoize' is safe is when you
  902.      are removing prototypes that were made with `protoize'; if the
  903.      program worked before without any prototypes, it will work again
  904.      without them.
  905.  
  906.      You can find all the places where this problem might occur by
  907.      compiling the program with the `-Wconversion' option.  It prints a
  908.      warning whenever an argument is converted.
  909.  
  910.    * Both conversion programs can be confused if there are macro calls
  911.      in and around the text to be converted.  In other words, the
  912.      standard syntax for a declaration or definition must not result
  913.      from expanding a macro.  This problem is inherent in the design of
  914.      C and cannot be fixed.  If only a few functions have confusing
  915.      macro calls, you can easily convert them manually.
  916.  
  917.    * `protoize' cannot get the argument types for a function whose
  918.      definition was not actually compiled due to preprocessing
  919.      conditionals.  When this happens, `protoize' changes nothing in
  920.      regard to such a function.  `protoize' tries to detect such
  921.      instances and warn about them.
  922.  
  923.      You can generally work around this problem by using `protoize' step
  924.      by step, each time specifying a different set of `-D' options for
  925.      compilation, until all of the functions have been converted.
  926.      There is no automatic way to verify that you have got them all,
  927.      however.
  928.  
  929.    * Confusion may result if there is an occasion to convert a function
  930.      declaration or definition in a region of source code where there
  931.      is more than one formal parameter list present.  Thus, attempts to
  932.      convert code containing multiple (conditionally compiled) versions
  933.      of a single function header (in the same vicinity) may not produce
  934.      the desired (or expected) results.
  935.  
  936.      If you plan on converting source files which contain such code, it
  937.      is recommended that you first make sure that each conditionally
  938.      compiled region of source code which contains an alternative
  939.      function header also contains at least one additional follower
  940.      token (past the final right parenthesis of the function header).
  941.      This should circumvent the problem.
  942.  
  943.    * `unprotoize' can become confused when trying to convert a function
  944.      definition or declaration which contains a declaration for a
  945.      pointer-to-function formal argument which has the same name as the
  946.      function being defined or declared.  We recommand you avoid such
  947.      choices of formal parameter names.
  948.  
  949.    * You might also want to correct some of the indentation by hand and
  950.      break long lines.  (The conversion programs don't write lines
  951.      longer than eighty characters in any case.)
  952.  
  953.